/*
 * @Author: LG
 * @Date: 2020-09-09 15:05:59
 * @Description: 
 * @Last Modified By: LG
 * @Last Modified Time: 2020-09-10 11:44:29
 */
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import React from 'react';

export const initialState:any = {
    user:sessionStorage.user?JSON.parse(sessionStorage.user):{
        name:'alex',age:'12'
    }
};
export const storeContext = React.createContext(initialState);
export const reducer = (state:any, action:any) => {
    console.log(action)
    switch (action.type) {
        case 'CHANGENAME':
            state.user.name=action.name
            sessionStorage.setItem('user', JSON.stringify(state.user));
            return {...state}
        case "CHANGEAGE":
            state.user.age=action.age
            sessionStorage.setItem('user', JSON.stringify(state.user));
            return {...state}
        case "CLEARDATA":
            sessionStorage.removeItem("user")
            state.user={}
            return {...state}
    }
};
